package com.itheima.order.web;

import com.itheima.feign.client.UserClient;
import com.itheima.feign.pojo.User;
import com.itheima.order.pojo.Order;
import com.itheima.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author 29143
 */
@RestController
@RequestMapping("/order")
public class OrderWeb {

    @Autowired
    private OrderService orderService;

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private UserClient userClient;


    @GetMapping("{id}")
    public Order findAllById(@PathVariable("id") Long id){

        //根据id查询订单并返回
        Order order = orderService.findAllById(id);

        //根据关联的userId远程查询用户信息
        User user = userClient.fiandById(order.getUserId());
        //将用户信息设置到订单种
        order.setUser(user);

        return order;
    }

    @GetMapping("/query")
    public String queryOrder(){
        return "查询订单成功";
    }

    @GetMapping("/update")
    public String updateOrder(){
        return "更新订单成功";
    }
    @GetMapping("/save")
    public String saveOrder(){
        //查询商品
        orderService.queryGoods();;
        System.err.println("新增订单");
        return "新增订单成功";
    }

}
